var t = getApp();

Page({
    data: {
        ht: {},
        url2: "",
        id: "",
        sessin: "",
        TopName: "",
        Listurl: "",
        img: "../../images/12.png",
        condition: !0,
        wxifnot: !0,
        netbol: !0,
        notebol: !1,
        btnbol: !0,
        From: "",
        inputTxt: "",
        E_mailurl: "EmailSubmit",
        canIu: !1
    },
    onLoad: function(a) {
        wx.showToast({
            title: "数据加载中",
            icon: "loading",
            duration: 2e4
        });
        var e = this, o = a.id, i = a.url;
        a.url2, t.globalData.htGet;
        wx.request({
            url: t.url + "addon/" + i,
            data: {
                id: o
            },
            method: "GET",
            header: {
                "Content-Type": "application/json",
                Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
            },
            success: function(o) {
                e.setData({
                    ht: o.data
                }), t.globalData.htGet = o.data, t.globalData.htGet.url = a.url, e.setData({
                    btnbol: !1
                }), wx.hideToast();
            },
            fail: function(t) {
                e.setData({
                    netbol: !1
                }), wx.hideToast(), wx.showToast({
                    title: "无法连接网络",
                    icon: "loading",
                    duration: 2200
                });
            }
        }), this.setData({
            url: a.url,
            url2: a.url2,
            id: a.id,
            sessin: a.sessin,
            Listurl: a.Listurl,
            TopName: a.TopName,
            From: a.From
        }), 1 == wx.canIUse("button.open-type.share") && this.setData({
            canIu: !0
        }), "Smcontract/Smcontract/" != a.Listurl && "Wdraft/Wdraft/" != a.Listurl || this.setData({
            copymail: "CopytoPC"
        }), "Model" == a.From && this.setData({
            copymail: "CopymailModel"
        });
    },
    onReady: function() {
        var t = this.data.sessin, a = wx.getStorageSync("PHPSESSID");
        t === a && a || this.sessValid();
    },
    edit: function() {
        var t = this.data.url, a = this.data.url2, e = this.data.id, o = this.data.sessin;
        wx.redirectTo({
            url: "../Modeledit/Modeledit?url=" + t + "&url2=" + a + "&id=" + e + "&sessin=" + o + "&Listurl=" + this.data.Listurl + "&TopName=" + this.data.TopName + "&From=" + this.data.From
        });
    },
    onShareAppMessage: function(t) {
        var a = this.data.Listurl, e = this.data.TopName, o = this.data.sessin, i = this.data.From;
        return this.setData({
            wxifnot: !0
        }), {
            title: this.data.ht.title,
            path: "/pages/Modelht/Modelht?id=" + this.data.id + "&url=" + this.data.url + "&url2=" + this.data.url2 + "&sessin=" + o + "&Listurl=" + a + "&TopName=" + e + "&From=" + i,
            success: function(t) {
                console.log(t);
            },
            fail: function(t) {}
        };
    },
    noEdit: function() {
        var t = this.data.id, a = this.data.url, e = this.data.sessin;
        wx.navigateTo({
            url: "../Modelht2/Modelht2?id=" + t + "&url=" + a + "&sessin=" + e + "&Listurl=" + this.data.Listurl + "&TopName=" + this.data.TopName + "&From=" + this.data.From
        });
    },
    toExam: function(t) {
        var a = this.data.Listurl;
        this.data.TopName;
        if ("Smcontract/Smcontract/" == a) e = "SM";
        if ("Wdraft/Wdraft/" == a) var e = "WT";
        var o = this.data.id;
        wx.navigateTo({
            url: "../../pages/ExamMy/ExamMy?id=" + o + "&htbase=" + e
        });
    },
    CopytoPC: function() {
        this.setData({
            condition: !1
        });
    },
    closeCluepage: function() {
        this.setData({
            condition: !0
        });
    },
    closeinfopage: function() {
        this.setData({
            wxifnot: !0
        });
    },
    openinfopage: function(a) {
        var e = this, o = a.currentTarget.dataset.index, i = this.data.ht.artlist, n = i[o].id, s = i[o].price;
        wx.showToast({
            title: "加载中",
            icon: "loading",
            duration: 2e4
        }), wx.request({
            url: t.url + "addon/Riskart/Riskart/artPayart",
            data: {
                id: n
            },
            method: "GET",
            header: {
                "Content-Type": "application/json",
                Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
            },
            success: function(a) {
                wx.hideToast(), 0 == a.data ? wx.showModal({
                    title: "提示",
                    content: "获取该文件内容，需付费" + s + "元，确定要支付吗？",
                    showCancel: !0,
                    confirmText: "前往支付",
                    success: function(a) {
                        if (a.confirm) {
                            console.log("用户点击确定"), wx.showToast({
                                title: "正在发起支付",
                                icon: "loading",
                                duration: 2e4
                            });
                            var l = wx.getStorageSync("userInfo");
                            wx.request({
                                url: t.url + "addon/Askplat/Askplat/charge",
                                data: {
                                    Amount: 100 * s,
                                    nickName: l.nickName,
                                    itemclass: "合同风险知识"
                                },
                                method: "POST",
                                header: {
                                    "content-type": "application/x-www-form-urlencoded",
                                    Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
                                },
                                success: function(a) {
                                    wx.hideToast(), wx.requestPayment({
                                        timeStamp: a.data.timeStamp,
                                        nonceStr: a.data.nonceStr,
                                        package: a.data.package,
                                        signType: "MD5",
                                        paySign: a.data.paySign,
                                        success: function(c) {
                                            console.log(c);
                                            var d = a.data.package.substr(10);
                                            wx.request({
                                                url: t.url + "addon/Riskart/Riskart/addRiskart",
                                                data: {
                                                    nickName: l.nickName,
                                                    paySum: s,
                                                    formId: d,
                                                    artId: n
                                                },
                                                method: "POST",
                                                header: {
                                                    "content-type": "application/x-www-form-urlencoded",
                                                    Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
                                                },
                                                success: function(t) {
                                                    console.log("id:", t.data), i[o].price = "已付", e.setData({
                                                        "ht.artlist": i
                                                    }), wx.hideToast();
                                                },
                                                fail: function(t) {
                                                    wx.hideToast(), wx.showModal({
                                                        title: "提示",
                                                        content: "因当前网络不稳定，造成创建工单失败，请尽快联系‘合同起草助手’客服",
                                                        showCancel: !1,
                                                        success: function(t) {
                                                            t.confirm ? console.log("用户点击确定") : t.cancel && console.log("用户点击取消");
                                                        }
                                                    });
                                                },
                                                complete: function(t) {}
                                            });
                                        }
                                    });
                                },
                                fail: function(t) {
                                    wx.hideToast(), wx.showToast({
                                        title: "无法连接网络",
                                        icon: "loading",
                                        duration: 2e3
                                    });
                                }
                            });
                        } else a.cancel && console.log("用户点击取消");
                    }
                }) : (e.setData({
                    riskart: a.data
                }), e.setData({
                    wxifnot: !1
                }));
            },
            fail: function(t) {
                wx.hideToast(), wx.showToast({
                    title: "无法连接网络",
                    icon: "loading",
                    duration: 2200
                });
            }
        });
    },
    CopymailModel: function() {
        var t = this;
        wx.showModal({
            title: "提示",
            content: "本小程序可以直接编辑文档，并可转发微信好友，还需要发送邮件吗？",
            confirmText: "发送邮件",
            cancelText: "取消发送",
            success: function(a) {
                a.confirm && t.setData({
                    condition: !1,
                    E_mailurl: "EmailModels"
                });
            }
        });
    },
    Operate: function() {
        var t = this, a = this.data.Listurl, e = this.data.From;
        "Smcontract/Smcontract/" != a && "Wdraft/Wdraft/" != a || wx.showActionSheet({
            itemList: [ "编辑合同", "委托审查合同", "只读模式", "发送至E-mail邮箱" ],
            success: function(a) {
                console.log(a.tapIndex), 0 == a.tapIndex && t.edit(), 1 == a.tapIndex && t.toExam(), 
                2 == a.tapIndex && t.noEdit(), 3 == a.tapIndex && t.CopytoPC();
            },
            fail: function(t) {
                console.log(t.errMsg);
            }
        }), "Model" == e && wx.showActionSheet({
            itemList: [ "编辑合同", "只读模式", "发送至邮箱" ],
            success: function(a) {
                console.log(a.tapIndex), 0 == a.tapIndex && t.edit(), 1 == a.tapIndex && t.noEdit(), 
                2 == a.tapIndex && t.CopymailModel();
            },
            fail: function(t) {
                console.log(t.errMsg);
            }
        });
    },
    toIndex: function() {
        var a = this.data.sessin, e = wx.getStorageSync("PHPSESSID"), o = (this.data.url, 
        this.data.From, "Modelstr_" + this.data.id);
        a && a == e ? wx.redirectTo({
            url: "../MyCenter/MyCenter?Listurl=" + this.data.Listurl + "&TopName=" + this.data.TopName
        }) : t.globalData[o] ? wx.redirectTo({
            url: "../Model/Model"
        }) : wx.switchTab({
            url: "../Draft/Draft"
        });
    },
    EmailSubmit: function(a) {
        console.log(a);
        var e = this, o = wx.getStorageSync("userInfo"), i = this.data.id, n = this.data.Listurl, s = a.detail.value.Email, l = this.Delplace(s), c = n + i, d = wx.getStorageSync(c) + parseInt(36e5);
        if (new Date().valueOf() <= d) wx.showModal({
            title: "提示",
            content: "您已经申请发送了该合同邮件，发送后须过1小时，方可就同一合同再次发送。如有急需，可联系客服。",
            showCancel: !1,
            success: function(t) {
                t.confirm || t.cancel;
            }
        }), this.setData({
            inputTxt: ""
        }); else {
            c = n + i;
            wx.removeStorageSync(c), (l.length <= 0 || !l) && wx.showToast({
                title: "未填写Email地址",
                icon: "loading",
                duration: 2e3
            }), l && l.length < 120 && (wx.showToast({
                title: "正在发送邮件",
                icon: "loading",
                duration: 2e4
            }), wx.request({
                url: t.url + "addon/" + n + "Mailsend",
                data: {
                    id: i,
                    Email: l,
                    nickName: o.nickName,
                    city: o.city
                },
                method: "POST",
                header: {
                    "content-type": "application/x-www-form-urlencoded",
                    Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
                },
                success: function(t) {
                    if (wx.hideToast(), console.log("结果为", t.data), 1 == t.data) {
                        e.setData({
                            inputTxt: ""
                        }), wx.showToast({
                            title: "提交发送成功",
                            icon: "success",
                            duration: 2e3
                        });
                        var a = n + i, o = new Date().valueOf();
                        wx.setStorageSync(a, o);
                    } else "timeout" == t.data ? (wx.showModal({
                        title: "提示",
                        content: "您已经申请发送了该合同邮件，发送后须过1小时，方可就同一合同再次发送。如有急需，可联系客服。",
                        showCancel: !1,
                        success: function(t) {
                            t.confirm ? console.log("用户点击确定") : t.cancel && console.log("用户点击取消");
                        }
                    }), e.setData({
                        inputTxt: ""
                    })) : (e.setData({
                        inputTxt: ""
                    }), "Todaytimeout" == t.data ? wx.showModal({
                        title: "提示",
                        content: "您今天已发送了超过20封合同邮件，投递员疲于往返，你也需要休息，明天再发可好？如有急需，可联系客服。",
                        showCancel: !1,
                        success: function(t) {
                            t.confirm || t.cancel;
                        }
                    }) : wx.showToast({
                        title: "发送邮件失败",
                        icon: "loading",
                        duration: 2200
                    }));
                },
                fail: function(t) {
                    wx.hideToast(), wx.showToast({
                        title: "无法连接网络",
                        icon: "loading",
                        duration: 2e3
                    }), e.setData({
                        inputTxt: ""
                    });
                }
            }));
        }
    },
    Delplace: function(t) {
        return t.replace(/(^\s*)|(\s*$)/g, "");
    },
    EmailModels: function(a) {
        console.log(a);
        var e = this, o = wx.getStorageSync("userInfo"), i = this.data.id, n = "Models/Models/", s = a.detail.value.Email, l = this.Delplace(s), c = n + i, d = wx.getStorageSync(c) + parseInt(36e5);
        if (new Date().valueOf() <= d) wx.showModal({
            title: "提示",
            content: "您已经申请发送了该合同邮件，发送后须过1小时，方可就同一合同再次发送。如有急需，可联系客服。",
            showCancel: !1,
            success: function(t) {
                t.confirm || t.cancel;
            }
        }), this.setData({
            inputTxt: ""
        }); else {
            c = n + i;
            wx.removeStorageSync(c), (l.length <= 0 || !l) && wx.showToast({
                title: "未填写Email地址",
                icon: "loading",
                duration: 2e3
            }), l && l.length < 120 && (wx.showToast({
                title: "正在发送邮件",
                icon: "loading",
                duration: 28e3
            }), wx.request({
                url: t.url + "addon/" + n + "Mailsend",
                data: {
                    id: i,
                    Email: l,
                    nickName: o.nickName,
                    city: o.city
                },
                method: "POST",
                header: {
                    "content-type": "application/x-www-form-urlencoded",
                    Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
                },
                success: function(t) {
                    if (wx.hideToast(), console.log("结果为", t.data), 1 == t.data) {
                        e.setData({
                            inputTxt: ""
                        }), wx.showToast({
                            title: "提交发送成功",
                            icon: "success",
                            duration: 2e3
                        });
                        var a = n + i, o = new Date().valueOf();
                        wx.setStorageSync(a, o);
                    } else "timeout" == t.data ? (wx.showModal({
                        title: "提示",
                        content: "您已经申请发送了该合同邮件，发送后须过1小时，方可就同一合同再次发送。如有急需，可联系客服。",
                        showCancel: !1,
                        success: function(t) {
                            t.confirm ? console.log("用户点击确定") : t.cancel && console.log("用户点击取消");
                        }
                    }), e.setData({
                        inputTxt: ""
                    })) : (e.setData({
                        inputTxt: ""
                    }), "Todaytimeout" == t.data ? wx.showModal({
                        title: "提示",
                        content: "您今天已发送了超过20封合同邮件，当日发送额度已用完，明天再发可好？如有急需，可联系客服。",
                        showCancel: !1,
                        success: function(t) {
                            t.confirm || t.cancel;
                        }
                    }) : wx.showToast({
                        title: "发送邮件失败",
                        icon: "loading",
                        duration: 2200
                    }));
                },
                fail: function(t) {
                    wx.hideToast(), wx.showToast({
                        title: "无法连接网络",
                        icon: "loading",
                        duration: 2e3
                    }), e.setData({
                        inputTxt: ""
                    });
                }
            }));
        }
    },
    sessValid: function() {
        wx.request({
            url: t.url + "addon/Pubdata/Pubdata/sessValid",
            data: {},
            method: "GET",
            header: {
                "Content-Type": "application/json",
                Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
            },
            success: function(a) {
                console.log(a.data), 0 == a.data && t.WxLogin();
            },
            fail: function(a) {
                t.WxLogin();
            }
        });
    }
});